package lab02.test23;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Test23 {
    //从命令行输入你的生日信息，然后计算你的生日还有多少天，你的生日是星期几
    public static void main(String[] args) throws ParseException {
        SimpleDateFormat now=new SimpleDateFormat("MM-dd");
        String a=now.format(new Date());
        Date a1=now.parse(a);

        SimpleDateFormat input=new SimpleDateFormat("MM-dd");
        Scanner bi=new Scanner(System.in);
        System.out.println("请输入你的生日：");
        String birth=bi.next();
        Date b1=now.parse(birth);
        Calendar call=Calendar.getInstance();
        call.setTime(new Date());
        int year=call.get(Calendar.YEAR);

        long dayBetween=(b1.getTime()-a1.getTime())/(3600*24*1000);

        if (dayBetween<=0){
            if ((year+1)%4==0&&(year+1)%100!=0||(year+1)%400==0){
                dayBetween+=366;
            }else{
                dayBetween +=365;
            }
        }
        System.out.println("现在" + "(" + now.format(new Date()) + ")" + "距你下次生日还有" + dayBetween + " 天");
        int j=(int)dayBetween%7;
        int i=call.get(Calendar.DAY_OF_WEEK);
        if (i==1){
            System.out.println("今天是星期日");
        }else{
            System.out.println("今天是星期"+(i-1));
        }
        if ((i+j-1)%7==0){
            System.out.println("当天是星期日");
        }else{
            System.out.println("当天是星期"+(i+j-1)%7);
        }
    }
}
